package com.sdhs.workflow.controller;


import com.sdhs.common.annotation.Log;
import com.sdhs.common.annotation.RepeatSubmit;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.domain.R;
import com.sdhs.common.core.page.PageQuery;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.validator.group.AddGroup;
import com.sdhs.common.utils.validator.group.EditGroup;
import com.sdhs.workflow.domain.bo.WfApproveUserConfigBo;
import com.sdhs.workflow.domain.vo.WfApproveUserConfigVo;
import com.sdhs.workflow.service.IWfApproveUserConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 流程审批人配置
 *
 * @author may
 * @date 2023-07-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workflow/approveUserConfig")
public class WfApproveUserConfigController extends BaseController {

    private final IWfApproveUserConfigService wfApproveUserConfigService;

    /**
     * 查询流程审批人配置列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfApproveUserConfigBo bo, PageQuery pageQuery) {
        return wfApproveUserConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取流程审批人配置详细信息
     *
     * @param id 主键
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:query')")
    @GetMapping("/{id}")
    public R<WfApproveUserConfigVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(wfApproveUserConfigService.queryById(id));
    }

    /**
     * 新增流程审批人配置
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:add')")
    @Log(title = "流程审批人配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<WfApproveUserConfigVo> add(@Validated(AddGroup.class) @RequestBody WfApproveUserConfigBo bo) {
        return R.ok(wfApproveUserConfigService.insertByBo(bo));
    }

    /**
     * 初始化数据
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:add')")
    @Log(title = "流程审批人配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/initData")
    public R<Boolean> initData() {
        return R.ok(wfApproveUserConfigService.initData());
    }

    /**
     * 修改流程审批人配置
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:edit')")
    @Log(title = "流程审批人配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<WfApproveUserConfigVo> edit(@Validated(EditGroup.class) @RequestBody WfApproveUserConfigBo bo) {
        return R.ok(wfApproveUserConfigService.updateByBo(bo));
    }

    /**
     * 删除流程审批人配置
     *
     * @param ids 主键串
     */
    @PreAuthorize("@ss.hasPermi('workflow:approveUserConfig:remove')")
    @Log(title = "流程审批人配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(wfApproveUserConfigService.deleteWithValidByIds(List.of(ids)));
    }
}
